const Koa = require('koa');
const app = new Koa();
const router = require('koa-router')()

app.use(async (ctx, next) => {
    let stime = new Date().getTime();
    await next();
    let etime = new Date().getTime();
    ctx.response.type = 'text/html';
    ctx.response.body = ` <h1>   hello, victor  </h1> `;
    console.log(`请求地址: ${ctx.path}，响应时间：${etime - stime}ms`)
})

app.use(async (ctx, next) => {
    console.log('中间件1 doSoming')
    await next();
    console.log('中间件1 end')
  })
  
  app.use(async (ctx, next) => {
    console.log('中间件2 doSoming')
    await next();
    console.log('中间件2 end')
  })
  
  app.use(async (ctx, next) => {
    console.log('中间件3 doSoming')
    await next();
    console.log('中间件3 end')
  })

let port = 3000;
app.listen(port, () => {
    console.log(' server is running at http://localhost:' + port);
})